package leetcode.m12;

public class Solution {
    public static int minSubArrayLen(int target, int[] nums) {
        int start = 0, end = 0;
        int sum = nums[0];
        int length = Integer.MAX_VALUE;
        while (end < nums.length) {
            if (sum < target) {
                end++;
                if (end < nums.length) {
                    sum += nums[end];
                }
            } else {
                if (end - start + 1 < length) {
                    length = end - start + 1;
                }
                sum -= nums[start];
                start++;
            }
        }

        return length == Integer.MAX_VALUE ? 0 : length;
    }

    public static void main(String[] args) {
        int[] a = {10,15,20};
        int i = minCostClimbingStairs(a);
        System.out.println(i);
    }
    //10,15,20
    public static int minCostClimbingStairs(int[] cost) {
        int[] d = new int[cost.length];
        d[0] = cost[0];
        d[1] = cost[1];
        for (int i = 2; i < d.length; i++) {
            int a = d[i - 1] + cost[i];
            int b = d[i - 2] + cost[i];
            d[i] = a<b?a:b;
        }
        return  Integer.min(d[cost.length-1],d[cost.length-2]);
    }

    public int integerBreak(int n) {
        return 0;
    }
}
